// pages/detailed/detailed.js
const app = getApp()
var utils = require('../../utils/util.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        curPage:1,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getTixianlist();
        this.getUserInfo();
        this.getSystemInfo();
    },
    //获取站点配置信息 
    getSystemInfo: function() {
        var that = this;
        utils.showLoading();
        utils.http("/api/v1/common/system", {}, function(res) {
            if (res.state == 1) {
                that.setData({
                    system: res.datas
                })
                utils.hideLoading();
            } else {
                utils.message(res.datas)
            }
        })
    },
    //学校列表
    getUserInfo: function () {
        var that = this;
        utils.showLoading();
        utils.http("/api/v1/member/index", {
        }, function (res) {
            if (res.state == 1) {
                that.setData({
                    user_info: res.datas
                })
                utils.hideLoading();
            } else {
                utils.hideLoading();
                utils.message(res.datas)
            }
        })
    },
    getTixianlist:function(){
        var that = this;
        var apiUrl = '/api/v1/member/withdrawal_log';
        var apiData = {
            page:that.data.curPage,
        }
        utils.http(apiUrl,apiData,function(res){
            if (res.state == 1) {
                var tixian_list = that.data.tixian_list || [];
                for (var i in res.datas) {
                    tixian_list.push(res.datas[i])
                }
                if (res.datas.length < 10) {
                    that.setData({
                        tishi_title: '已加载全部',
                    });
                } else {
                    that.setData({
                        tishi_title: '正在加载中...',
                    });
                }
                that.setData({
                    tixian_list: tixian_list,
                    ready: res.datas.length == 0 ? 1 : 2,
                })
            } else {
                utils.message(res.datas)
            }
        });
    },
    makeWith:function(){
        var that = this;
		if (that.data.user_info.rate_predeposit > that.data.system.member_mini_cash_with){
            utils.confirm('您确定提现吗？',function(res){
                utils.showLoading();
                var apiUrl = '/api/v1/member/withdrawal';
                var apiData = {
                }
                utils.http(apiUrl,apiData,function(res){
                    if (res.state == 1) {
                        utils.showSuccess(res.datas);
                        setTimeout(function(){
                            that.getTixianlist();
                            that.getUserInfo();
                            that.getSystemInfo();
                        },2000);
                        utils.hideLoading();
                    } else {
                        utils.hideLoading();
                        utils.message(res.datas)
                    }
                });
            })
        }else{
            utils.showTishi('满'+that.data.system.member_mini_cash_with+'元才可以提现');
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
         var that = this;
        if (that.data.ready == 2) {
            var page = that.data.curPage + 1
            that.setData({
                curPage: page,
            })
            that.getTixianlist();
        }
    },  

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})